
***************************************************
* Figure C.1 and C.2
***************************************************
***************************************************
* Figure C.1, 1-7, and C.2, 1-7
***************************************************

use "$workdata/baseline", clear /* see $data_do/baseline.do */


collapse wage sa (sum) e, by(pnr age_q year) 

capture drop age_month_q_y
g age_month_q_y=floor(age_q)
tostring age_month_q_y, replace
capture drop age_month_q_m
g age_month_q_m=(round((age_q-floor(age_q))*12)+1)/100
tostring age_month_q_m, replace
capture drop age_month_q
egen age_month_q=concat(age_month_q_y age_month_q_m)
destring age_month_q, replace
local resp="age_month_q>=24.12 & age_month_q<=25.04"
g resp=`resp'
g d=age_q>=25
g age_q0=age_q-25
g age_q0_2= age_q0^2
g age_q0_3= age_q0^3
g dXage_q0=d*age_q0
g dXage_q0_2=d*age_q0_2
g dXage_q0_3=d*age_q0_3

*********************************************************************

eststo clear
local model=0
foreach y of varlist wage sa {
local num=0
forvalues year=2000/2006 {  
local num=`num'+1
preserve
keep if year==`year'      
keep if age_q>=21 & age_q<29
if `y'==wage local title="Employment"
if `y'==sa   local title="Social Assistance"
if `y'==wage local C=2
if `y'==sa   local C=1
local min_wage=0.49
local max_wage=0.59
local min_sa  =0.09
local max_sa  =0.19

local spec_name="2nd order polynomial spline"
local spec="d age_q0 age_q0_2      dXage_q0 dXage_q0_2"

local model =`model'+1
local repl_app="append"
if `model'==1 local repl_app="replace"

eststo model`model': reg `y' `spec' [aw=e] if resp==0 , vce(cluster pnr)

predict yhat
local beta_d=round(_b[d], .001)*10000
local beta_d=floor(`beta_d')/100 
di `beta_d' 
collapse `y' yhat (sem) se=`y'  [aw=e], by(age_q)
g `y'_min=`y'-se*1.96
g `y'_max=`y'+se*1.96
capture drop age_month_q_y
g age_month_q_y=floor(age_q)
tostring age_month_q_y, replace
capture drop age_month_q_m
g age_month_q_m=(round((age_q-floor(age_q))*12)+1)/100
tostring age_month_q_m, replace
capture drop age_month_q
egen age_month_q=concat(age_month_q_y age_month_q_m)
destring age_month_q, replace
local resp="age_month_q>=24.12 & age_month_q<=25.04"
g resp=`resp'
twoway (rarea `y'_min `y'_max age_q if age_month_q<24.12, color(gs13)) ///
	   (rarea `y'_min `y'_max age_q if age_month_q>25.04, color(gs13)) ///
	   (line yhat age_q if age_q< 25    & resp==0, lcolor(gs3)) ///
   	   (line yhat age_q if age_q>= 25   & resp==0, lcolor(gs3)) ///
	   (scatter `y' age_q if age_q< 25  , msymbol(o) mlcolor(gs3) mfcolor(gs14))  ///
	   (scatter `y' age_q if age_q>=25  , msymbol(o) mlcolor(gs3) mfcolor(gs14)) ///
	   (scatter `y' age_q if `resp', msymbol(o) mlcolor(gs3) mfcolor(gs16)) ///
	    , ylabel(`min_`y''(0.02)`max_`y'') ytitle(`title', height(5))  ///
	     xlabel(21(1)29)        xtitle("Age in months", height(5))      ///
	     xline(24.958333, lpattern(solid)) xline(25.291667, lpattern(dash)) scheme(s1mono) legen(off) name(figC_`y'_`num', replace) note("Year: `year', Effect size: `beta_d' pp (Specification: `spec_name')" )

graph save figC_`y'_`num'  $figures/figC_`y'_`num', replace
graph export $figures/figC_`y'_`num'.pdf, name(figC_`y'_`num') replace
graph export $figures/figC_`y'_`num'.png, name(figC_`y'_`num') replace

restore
}
}  

***************************************************
* Figure C.1, 8, and C.2, 8
***************************************************

use "$workdata/baseline", clear /* see $data_do/baseline.do */

collapse wage sa (sum) e, by(pnr age_q) 

capture drop age_month_q_y
g age_month_q_y=floor(age_q)
tostring age_month_q_y, replace
capture drop age_month_q_m
g age_month_q_m=(round((age_q-floor(age_q))*12)+1)/100
tostring age_month_q_m, replace
capture drop age_month_q
egen age_month_q=concat(age_month_q_y age_month_q_m)
destring age_month_q, replace
local resp="age_month_q>=24.12 & age_month_q<=25.04"
g resp=`resp'
g d=age_q>=25
g age_q0=age_q-25
g age_q0_2= age_q0^2
g age_q0_3= age_q0^3
g dXage_q0=d*age_q0
g dXage_q0_2=d*age_q0_2
g dXage_q0_3=d*age_q0_3

*********************************************************************

foreach y of varlist wage sa {
forvalues s=2/2 {
preserve
keep if age_q>=21 & age_q<29
local spec_num=`s'
if `y'==wage local title="Employment"
if `y'==sa   local title="Social Assistance"
if `y'==wage local C=2
if `y'==sa   local C=1
if `y'==wage local num=8
if `y'==sa local num=8


local min_wage=0.49
local max_wage=0.59
local min_sa  =0.09
local max_sa  =0.19
if `spec_num'==1 local spec="d age_q0                   dXage_q0"
if `spec_num'==2 local spec="d age_q0 age_q0_2          dXage_q0 dXage_q0_2"
if `spec_num'==3 local spec="d age_q0 age_q0_2 age_q0_3 dXage_q0 dXage_q0_2 dXage_q0_3"
if `spec_num'==4 local spec="d age_q0"
if `spec_num'==5 local spec="d age_q0 age_q0_2"
if `spec_num'==6 local spec="d age_q0 age_q0_2 age_q0_3"
if `spec_num'==1 local spec_name="1st order polynomial spline"
if `spec_num'==2 local spec_name="2nd order polynomial spline"
if `spec_num'==3 local spec_name="3rd order polynomial spline"
if `spec_num'==4 local spec_name="1st order polynomial"
if `spec_num'==5 local spec_name="2nd order polynomial"
if `spec_num'==6 local spec_name="3rd order polynomial"
local model =`model'+1
local repl_app="append"
if `model'==1 local repl_app="replace"
eststo model`model': reg `y' `spec' [aw=e] if resp==0 ,  vce(cluster pnr)


predict yhat
local beta_d=round(_b[d], .001)*10000
local beta_d=floor(`beta_d')/100 
collapse `y' yhat (sem) se=`y'  [aw=e], by(age_q)
g `y'_min=`y'-se*1.96
g `y'_max=`y'+se*1.96
capture drop age_month_q_y
g age_month_q_y=floor(age_q)
tostring age_month_q_y, replace
capture drop age_month_q_m
g age_month_q_m=(round((age_q-floor(age_q))*12)+1)/100
tostring age_month_q_m, replace
capture drop age_month_q
egen age_month_q=concat(age_month_q_y age_month_q_m)
destring age_month_q, replace
local resp="age_month_q>=24.12 & age_month_q<=25.04"
g resp=`resp'
twoway (rarea `y'_min `y'_max age_q if age_month_q<24.12, color(gs13)) ///
	   (rarea `y'_min `y'_max age_q if age_month_q>25.04, color(gs13)) ///
	   (line yhat age_q if age_month_q<24.12 & `y'>`min_`y'' & `y'<`max_`y'', lcolor(gs3)) ///
   	   (line yhat age_q if age_month_q>25.04 & `y'>`min_`y'' & `y'<`max_`y'', lcolor(gs3)) ///
	   (scatter `y' age_q if age_q< 25 & `y'>`min_`y'' & `y'<`max_`y'', msymbol(o) mlcolor(gs3) mfcolor(gs14))  ///
	   (scatter `y' age_q if age_q>=25 & `y'>`min_`y'' & `y'<`max_`y'', msymbol(o) mlcolor(gs3) mfcolor(gs14)) ///
	   (scatter `y' age_q if `resp', msymbol(o) mlcolor(gs3) mfcolor(gs16)) ///
	    , ylabel(`min_`y''(0.02)`max_`y'') ytitle(`title', height(5))  ///
	     xlabel(21(1)29)        xtitle("Age in months", height(5))      ///
	     xline(24.958333) xline(25.291667, lpattern(dash)) scheme(s1mono) legen(off) name(figC_`y'_`num', replace) note("Years: 2000-2006, Effect size: `beta_d' pp (Specification: `spec_name')") 
		 
graph save figC_`y'_`num'  $figures/figC_`y'_`num', replace
graph export $figures/figC_`y'_`num'.pdf, name(figC_`y'_`num') replace
graph export $figures/figC_`y'_`num'.png, name(figC_`y'_`num') replace

restore
}
}


graph use "$figures\figC_sa_1"
graph use "$figures\figC_sa_2"
graph use "$figures\figC_sa_3"
graph use "$figures\figC_sa_4"
graph use "$figures\figC_sa_5"
graph use "$figures\figC_sa_6"
graph use "$figures\figC_sa_7"
graph use "$figures\figC_sa_8"
graph combine figC_sa_1 figC_sa_2 figC_sa_3 figC_sa_4 figC_sa_5 figC_sa_6 figC_sa_7 figC_sa_8 ///
, cols(2) rows(4) ysize(16) xsize(11) altshrink graphregion(margin(zero)) scheme(s1mono) name(figC1, replace)
graph save figC1  $figures/figC1, replace
graph export $figures/figC1.pdf, name(figC1) replace
graph export $figures/figC1.png, name(figC1) replace

graph use "$figures\figC_wage_1"
graph use "$figures\figC_wage_2"
graph use "$figures\figC_wage_3"
graph use "$figures\figC_wage_4"
graph use "$figures\figC_wage_5"
graph use "$figures\figC_wage_6"
graph use "$figures\figC_wage_7"
graph use "$figures\figC_wage_8"
graph combine figC_wage_1 figC_wage_2 figC_wage_3 figC_wage_4 figC_wage_5 figC_wage_6 figC_wage_7 figC_wage_8 ///
, cols(2) rows(4) ysize(16) xsize(11) altshrink graphregion(margin(zero)) scheme(s1mono) name(figC2, replace)
graph save figC2  $figures/figC2, replace
graph export $figures/figC2.pdf, name(figC2) replace
graph export $figures/figC2.png, name(figC2) replace


***************************************************
* end: Figure C.1 and C.2
***************************************************

